/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package netexpwithoutui.tools;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author hxd
 */
public class UdpPacket {
    public static DatagramPacket setDatagramPacket(String text,String ip,int port){
        try {
            byte[] buf=text.getBytes();
            InetAddress addr=InetAddress.getByName(ip);
            return new DatagramPacket(buf,buf.length,addr,port);
        } catch (UnknownHostException ex) {
            Logger.getLogger(UdpPacket.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
}
